﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Pyramid_Game
{
    class Pick
    {
        #region Declarations

        Rectangle position = new Rectangle();
        List<int> positionList = new List<int>();
        Point touchPosition = new Point();
        float savePosition = 0;

        #endregion

        #region Property

        public Rectangle Position
        {
            set { position = value; }
            get { return position; }
        }
        #endregion

        #region Constructor

        public Pick()
        {
            position = new Rectangle(400, 480, 100, 100);

            positionList.Add(0);
            positionList.Add(100);
            positionList.Add(200);
            positionList.Add(300);
            positionList.Add(400);
            positionList.Add(500);
            positionList.Add(600);
            positionList.Add(700);
            positionList.Add(800);
        }
        public void Update(Point touchPoint)
        {
            touchPosition = touchPoint;

            for (int i = 0 ; i<8 ; i++)
            {
                if(touchPoint.X >= positionList[i] && touchPoint.X <= positionList[i+1])
                {
                    savePosition = i*100 + 50;
                }
            }

            if (savePosition > 400)
            {
                position.X += (int)(System.Math.Abs(400 - savePosition)) / 20;
            }
            else
            {
                position.X -= (int)(System.Math.Abs(400 - savePosition)) / 20;
            }
            position.Y -= (System.Math.Abs(480 - touchPoint.Y)) / 20;
        }
        public void Update()
        {
            for (int i = 0; i < 8; i++)
            {
                if (touchPosition.X >= positionList[i] && touchPosition.X <= positionList[i + 1])
                {
                    savePosition = i * 100 + 50;
                }
            }

            if (savePosition > 400)
            {
                position.X += (int)(System.Math.Abs(400 - savePosition)) / 20;
            }
            else
            {
                position.X -= (int)(System.Math.Abs(400 - savePosition)) / 20;
            }
            position.Y -= (System.Math.Abs(480 - touchPosition.Y)) / 20;
        }

        public void Initialize()
        {
            position.X = 400;
            position.Y = 480;
        }
        #endregion
    }
}
